package com.tr.lambda;

/**
 * @author TRasdzz
 * @since  2021/3/10 11:32
 * @version 1.0
 */
/*
推导lambda表达式
 */
public class TestLambda01 {
    //3. 静态内部类
    static class like2 implements ILike{

        @Override
        public void lambda() {
            System.out.println("I like lambda2");
        }
    }

    public static void main(String[] args) {
        ILike like = new like();
        like.lambda();

        like = new like2();
        like.lambda();

        //4.局部内部类
        class Like3 implements ILike{

            @Override
            public void lambda() {
                System.out.println("I like lambda3");
            }
        }

        like = new Like3();
        like.lambda();

        //5. 匿名内部类,没有类的名称，必须借助接口或者父类
        like = new ILike() {
            @Override
            public void lambda() {
                System.out.println("I like lambda4");
            }
        };
        like.lambda();

        //6. lambda简化
        like = () ->{
            System.out.println("I like lambda5");
        };
        like.lambda();

    }

}

//1. 需要一个接口
interface ILike{
    void lambda();
}

//2.实现类
class like implements ILike{

    @Override
    public void lambda() {
        System.out.println("I like lambda1");
    }
}

//I like lambda1
//I like lambda2
//I like lambda3
//I like lambda4
//I like lambda5
